package cn.lixu.controller;

import cn.lixu.block.UserBlock;
import cn.lixu.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiXu
 * @date 2022/08/23 0023 10:56:16
 */
@RestController
@RequestMapping("/user")
@RefreshScope // 动态刷新配置注解
public class UserController {

    @Value("${test.name}")
    private String name;

    //提供一个根据Id返回User对象的接口，给order服务调用
    @GetMapping("/getById/{id}")
    @SentinelResource(value = "user-service",blockHandler = "sentinelMethod",blockHandlerClass = UserBlock.class)
    public User getById(@PathVariable("id") Long id) {
        return new User(id, "麻豆传媒", "诚招男演员，面谈" + "," + name);
    }

/**
 *@author lixu
 *@data 2022/08/23 0023 13:13:47
 * @param: null
 * @return: null
 * 服务降级方法【兜底数据】
 **/
   /* public User sentinelMethod(@PathVariable("id") Long id, BlockException e) {
        e.printStackTrace();
        return new User(-1L, "服务降级触发", "快去了，快去了，那里不行" );
    }*/
}
